﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dln.Common.Helper;
using Dln.Handler;
using Dln.Model;
using Quartz;

namespace AutoRun
{
    public class SendproblemComplete : IJob
    {

        private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        public void Execute(IJobExecutionContext context)
        {
            log4net.Config.XmlConfigurator.Configure();
            Log.InfoFormat("category The current time is: {0}", DateTime.Now);

            var dtTypeList = SqlHelper.ContextDlnOnline.FromSql("SELECT * FROM dt_order with(nolock) where state=1 and  datediff(Minute,CONVERT(varchar(100), update_time, 20),GETDATE()) >60 ").ToList<dt_order>();
            if (dtTypeList != null && dtTypeList.Count() > 0)
            {
                foreach (var item in dtTypeList)
                {
                    if (!string.IsNullOrEmpty(item.update_name))
                    {
                        var weChatUsersList = SqlHelper.Context.From<WeChatUsers>().Where(d => d.CardID == item.update_name).ToFirst();
                        if (weChatUsersList != null)
                        {
                            Log.InfoFormat("接单未完成：" + weChatUsersList.Openid + item.id.ToString());
                            MessageHelper.ProblemNotice(weChatUsersList.Openid,
                                            "该问题已被您接收处理，请确认是否处理完毕",
                                          item.add_time,
                                           "问题报修",
                                           "标题:" + item.title,
                                            "http://www.healthyperson.cn/Page/AutoRun/SendProblem.aspx?Id=" + item.id + "&cardId=" + weChatUsersList.CardID
                                        );
                        }
                    }
                }
            }

            Log.InfoFormat("结束");
        }
    }
}
